<template>
	<view>
		<scroll-view scroll-y="true" :style="'height:'+scrollH+'px;'" @scrolltolower="loadMore()">
			<template v-if=" list.length > 0">
		<block v-for="(item,index) in list" :key="index">
	            <common-list :item="item" :index="index">
				</common-list>
				<divider></divider>
		    </block>
		   <load-more :loadmore="loadmore"></load-more>
		   </template>
		   <template v-else-if="!this.firstLoad">
		   <view class="flex align-center justify-center">
		   <text class="font-md text-light-muted">加载中</text>
		    </image>
		   </view>		
		      </template>
		   <template v-else>
		<view class="flex align-center justify-center">
		 <image src="/static/img/nothing.jpg" >
		 </image>
		</view>		
		   </template>
		  
			</scroll-view>
		  </view>
</template>

<script>

	import commonList from '@/components/common/common-list.vue';
	import loadMore from '@/components/common/load-more.vue';
	import { mapState } from 'vuex';
	export default {
		components:{commonList,loadMore},
		data() {
			return {
				scrollH:300,
				loadmore:'上拉加载更多',
				firstLoad:false,
				pagnation:{
					pageNum:1,
					pageSize:10
				},
				list:[]
			}
		},
		computed:{
			...mapState({
				loginStatus:state=>state.loginStatus
			})
		},
		onNavigationBarSearchInputClicked(){
		    uni.navigateTo({
		    	url: '../serach/serach',
		    });	
		},
		onNavigationBarButtonTap() {
			this.navigateTo({
				url:'../add/add'
			})
		},
		onLoad() {
			this.getData()
            uni.getSystemInfo({
            	success: (res) => {
            		this.scrollH = res.windowHeight;
            	}
            }),
			uni.$on('updateIndex',()=>{
				this.getData()
			})
		},
		onUnload() {
			uni.$off('updateIndex',(e)=>{})
		},
		methods: {
            loadMore(){
				if(this.loadmore !== "上拉加载更多") return;
				this.loadmore ="加载中..."
				this.pagnation.pageNum++
				this.getData();
  
			},
			getData(){
				const data={
				    ...this.pagnation
				}
				let temp = this.list;
				if(this.loginStatus){
				this.$R.get('/meet/event/listToken',data).then((res)=>{
				 if(res.code ==200){
				   this.list = this.pagnation.pageNum==1?res.rows:[...res.rows,...temp],
					this.loadmore = res.rows.length<10?'没有更多了':'上拉加载更多'
					if(!this.firstLoad){
						this.firstLoad = true
					}
					}else if(res.code == 401){
						uni.navigateTo({
							url:'../login/login'
						})
					}
				})
			    }else{
					this.$R.getNoToken('/meet/event/list',data).then((res)=>{
						
					   this.list = this.pagnation.pageNum==1?res.rows:[...res.rows,...temp],
						this.loadmore = res.rows.length<10?'没有更多了':'上拉加载更多'
						if(!this.firstLoad){
							this.firstLoad = true
						}
						
					})
				}
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
